{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置输入曲线范围,由于取了对数，所以RD和RS设置下限-1\n",
    "AC = [40,140]\n",
    "CNL = [-0.15,0.45]\n",
    "DEN = [1.2,3.2]  # 正常：[2,3] # TT1：4000-4600\n",
    "GR = [0,450]\n",
    "RD = [-2,7]\n",
    "RS = [-2,7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 元素参数范围\n",
    "Al = [0,0.25]    # 正常：[0,0.15]\n",
    "Ca = [0,0.5]  # 正常：[0,0.4]\n",
    "Fe = [0,0.15] # 正常：[0,0.1]\n",
    "K = [0,0.1]  # 正常： [0,0.15]\n",
    "Mg = [0,0.4]\n",
    "Na = [-0.01, 0.04]  # TT1 [0,0.03]  J404 [0,0.05]\n",
    "Si = [0,0.6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "u_log = {\"AC\": AC, \"CNL\": CNL, \"DEN\": DEN, \"GR\": GR, \"RD\": RD, \"RS\": RS}\n",
    "e_log = {\"Al\": Al, \"Ca\": Ca, \"Fe\": Fe,\"K\": K, \"Mg\": Mg, \"Na\":Na, \"Si\": Si}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 写入Json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 写入 JSON 数据\n",
    "with open('u_log.json', 'w') as f:\n",
    "    json.dump(u_log, f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# e_log_content = str(e_log)\n",
    "with open('e_log.json', 'w') as f_six:\n",
    "    json.dump(e_log, f_six)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 从Json读入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'AC': [40, 140], 'CNL': [-0.15, 0.45], 'DEN': [1.2, 3.2], 'GR': [0, 450], 'RD': [-2, 7], 'RS': [-2, 7]}\n"
     ]
    }
   ],
   "source": [
    "# 读取数据\n",
    "with open('u_log.json', 'r') as f:\n",
    "    u_log_data = json.load(f)\n",
    "print(u_log_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[40, 140]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "u_log_data['AC']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Al': [0, 0.25], 'Ca': [0, 0.5], 'Fe': [0, 0.15], 'K': [0, 0.1], 'Mg': [0, 0.4], 'Na': [-0.01, 0.04], 'Si': [0, 0.6]}\n"
     ]
    }
   ],
   "source": [
    "with open('e_log.json', 'r') as f_six:\n",
    "    e_log_data = json.load(f_six)\n",
    "print(e_log_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 0.25]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e_log_data[\"Al\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
